﻿using System;
using System.Collections.Generic;
using System.Linq;
using CondeNet.AssetManager.Business.Interface;
using CondeNet.FoundationServices.ObjectManagement;
using CondeNet.AssetManager.DataProvider.Sql.Entities;

namespace CondeNet.AssetManager.DataProvider.Sql
{
    public class TypeFunctionsLookup
    {
        public static TypeFunctionsLookup Current
        {
            get
            {
                return Singleton<TypeFunctionsLookup>.AppScoped; 
            }
        }

        public List<TypeFunction> SourceDbTypeFunctions = null;

        public TypeFunctionsLookup()
        {
            SourceDbTypeFunctions = (from tf in Singleton<AssetManagerDataContext>.AppScoped.TypeFunctions select tf).ToList();
        }

        public static TypeOfContent GetStronglyTypedFunction (int functionId)
        {
            TypeFunction referred =
                (from tf in Current.SourceDbTypeFunctions where tf.TypeFunctionID == functionId select tf).First();
            switch (referred.Name.ToLowerInvariant())
            {
                case "image":
                    return TypeOfContent.Image;
                    break;
                case "video":
                    return TypeOfContent.Video;
                default:
                    goto case "image";
            }
        }
        public static short GetFunctionId(TypeOfContent type)
        {
            //todo: perform this in a different way
            TypeFunction referred =
                (from tf in Current.SourceDbTypeFunctions
                 where tf.Name.ToLowerInvariant() == type.ToString().ToLowerInvariant()
                 select tf).First();
            return referred.TypeFunctionID;
        }
    }
}
